package ua.mykola.backtracking;

public abstract class Backtrack {

	public void backtrack(int[] a, int current, int input) {
		if (isSolution(a, current, input)) {
			processSolution(a, current);
		} else {
			current++;
			int[] candidates = constructCandidates(a, current, input);
			for (int i = 0; i < candidates.length; i++) {
				a[current - 1] = candidates[i];
				backtrack(a, current, input);
			}
		}
	}

	abstract void processSolution(int[] a, int k);

	abstract boolean isSolution(int[] a, int k, int input);

	abstract int[] constructCandidates(int[] a, int k, int input);
}
